//
//  InspirationTableViewCell.m
//  grainHouse
//
//  Created by zzxcc on 14-10-17.
//  Copyright (c) 2014年 zzxcc. All rights reserved.
//

#import "InspirationTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "InsData.h"
#import "InsModel.h"

@interface InspirationTableViewCell()

@property(nonatomic, retain)UIView *vieww;
@property(nonatomic, retain)NSMutableArray *arry;
@property(nonatomic, retain)UIView *vieww2;
@property(nonatomic, retain)UIScrollView *scrollview;
@property(nonatomic, retain)NSMutableArray *array;


@end

@implementation InspirationTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
}


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
     
        
        [self creatView];
        
    }
    return self;
}

- (void)creatView
{
    self.vieww = [[UIView alloc] initWithFrame:CGRectZero];
    
    self.button = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
    self.button.backgroundColor = [UIColor redColor];
    //[self.button setImage:[UIImage imageNamed:@"default_avatar" ] forState:UIControlStateNormal];
    [self.contentView addSubview:_button];
    
    
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 58, 50, 20)];
    //_nameLabel.text = @"姓名";
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_nameLabel];
    [_nameLabel release];
    
    
    self.titleLabel= [[UILabel alloc]initWithFrame:CGRectMake(60, 5, 250, 50)];
    self.titleLabel.backgroundColor = [UIColor yellowColor];
    //self.titleLabel.text = @"这是一个标题式样!!!!";
    self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 58, 120, 16)];
    //self.timeLabel.backgroundColor = [UIColor blueColor];
    _timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    //self.timeLabel.text = @"2014-02-11 11:08";
    [self.contentView addSubview:_timeLabel];
    [_timeLabel release];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 80, 305, 50)];
    [_contentLabel setNumberOfLines:0];
    _contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    _contentLabel.adjustsFontSizeToFitWidth = YES;
    _contentLabel.font = [UIFont systemFontOfSize:15];
    //_contentLabel.text = @"大开发和的卡是废话卡斯看看大声疾呼嗲说非说i 收到回复i 是回复地上i 收到回复 i是东方红是地方是地方i 收到回复打司机放萨打开打瞌睡可是打扮可是打开";
    _contentLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:_contentLabel];
    [_contentLabel release];
    
    
 
    
    //滚动视图
    
    _arry = [[NSMutableArray alloc] initWithObjects:@"1.jpg", @"2.jpg", @"3.jpg", nil];
    
    _view1 = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 135, 300, 140)];
    _view1.contentSize = CGSizeMake(460, 140) ;
    _view1.pagingEnabled = YES;
    _view1.scrollsToTop = YES;
    _view1.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_view1];
    [_view1 release];
    
    //获取insdata中的数据
    
    //NSLog(@"id===%@",[_array[0] photos] );
    for (int i = 0; i < 3; i ++) {
        
        //http://gooju.cn/dimages/587299_0_w600_h0_m0.jpg
        self.view2 = [[UIImageView alloc] initWithFrame:CGRectMake(150 * i, 0, 140, 140)];
        //_view2.image = [UIImage imageNamed:[_arry objectAtIndex:i]];
//        [ _view2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w600_h0_m0.jpg", [[_array[1] photos][i] valueForKey:@"id"]]]placeholderImage:nil options:SDWebImageRefreshCached];
        _view2.tag = i + 1;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        _view2.userInteractionEnabled = YES;
        _view2.backgroundColor = [UIColor blackColor];
        [_view2 addGestureRecognizer:tap];
        [_view1 addSubview:_view2];
        [_view2 release];
    }
    
    

    
    
}

- (void)tapAction:(UITapGestureRecognizer *)sender
{
   // NSLog(@"ds");
    UIGestureRecognizer *gesture = (UIGestureRecognizer *)sender;
    UIImageView *imageView = (UIImageView *)gesture.view;
    
    NSArray *imagArr = [[imageView superview]subviews];
    NSUInteger index = [imagArr indexOfObject:imageView];
    
    [UIView animateWithDuration:0.3 animations:^{
        
        _vieww.Frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
        _vieww.backgroundColor = [UIColor blackColor];
        //_vieww.alpha = 0.9;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapBGviewAction:)];
        
        [_vieww addGestureRecognizer:tap];
        
        
        self.vieww2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, _vieww.frame.size.width-40, _vieww.frame.size.height-40)];
        [_vieww addSubview:_vieww2];
        [_vieww2 release];
        
        self.scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, _vieww2.frame.size.width, _vieww2.frame.size.height)];
        _scrollview.contentOffset = CGPointMake(_vieww2.frame.size.width*index, 0);
        _scrollview.contentSize = CGSizeMake(_vieww2.frame.size.width * 3, _vieww2.frame.size.height);
        _scrollview.delegate = self;
        _scrollview.pagingEnabled = YES;
        _scrollview.showsHorizontalScrollIndicator = NO;
        
        
        [_vieww2 addSubview:_scrollview];
        
        
        
        
        
        //    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 100, 100)];
        
        [self.contentView addSubview:_vieww];
        
    } completion:^(BOOL finished) {
        
        for (int i = 0; i < 3; i++)
        {
            //                UIImageView *image = [imageArr1 objectAtIndex:i];
            UIImageView *imageView = [[UIImageView alloc] init];
          [ imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w600_h0_m0.jpg", [[_array[0] photos][i] valueForKey:@"id"]]]placeholderImage:nil options:SDWebImageRefreshCached];
            imageView.tag = 100 + i;
            imageView.frame = CGRectMake(_scrollview.frame.size.width * i + 15, 0, 250, 250);
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            
            [_scrollview addSubview:imageView];
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(_scrollview.frame.size.width/2 + _scrollview.frame.size.width * i - 45, _scrollview.frame.size.height - 30, 100, 40)];
            //label.text = [NSString stringWithFormat:@"%d/3",i+1];
            label.tag = 1000+i;
            label.textColor = [UIColor redColor];
            [_scrollview addSubview:label];
        }
    }];
    
}

-(void)TapBGviewAction:(UITapGestureRecognizer *)sender
{
    [UIView animateWithDuration:0.3 animations:^{
        
        _vieww.frame = CGRectZero;
        for(int i = 0;i < 3;i++)
        {
            UIImageView *imageview = (UIImageView *)[self.contentView viewWithTag:100+i];
            UILabel *label = (UILabel *)[self.contentView viewWithTag:1000+i];
            [label removeFromSuperview];
            [imageview removeFromSuperview];
        }
    } completion:^(BOOL finished) {
        
        [_vieww removeFromSuperview];
    }];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
